package com.example.demo;

import java.util.function.Consumer;
import java.util.function.Supplier;
import org.springframework.util.StopWatch;

/**
 * @author：zzc
 * @date: 2022/8/30
 */
public class StopWatchTemplate {

    public static <T> T doSupplier(Supplier<T> supplier) {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        T t = supplier.get();
        stopWatch.stop();
        System.out.println("共耗时："+stopWatch.getTotalTimeMillis()+"/ms");
        return t;
    }

    public static <T> void doConsumer(Consumer<T> consumer) {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        consumer.accept(null);
        stopWatch.stop();
        System.out.println("共耗时："+stopWatch.getTotalTimeMillis()+"/ms");
    }



}
